package pub.cleangao.mybatis.expression;


import lombok.Setter;

@Setter
public class BetweenExpression implements WhereExpressionBetween {

    private WhereJoint whereJoint;
    private String column;
    private Object startValue;
    private Object endValue;
    private WhereOperator whereOperator;
    private int index;

    public static WhereExpression buildExpression(WhereJoint whereJoint, String columnName, Object startValue, Object endValue, int... index) {
        BetweenExpression betweenExpression = new BetweenExpression();
        betweenExpression.setWhereJoint(whereJoint);
        betweenExpression.setColumn(columnName);
        betweenExpression.setWhereOperator(WhereOperator.between);
        betweenExpression.setStartValue(startValue);
        betweenExpression.setEndValue(endValue);
        if (index != null && index.length > 0) {
            betweenExpression.setIndex(index[0]);
        }
        return betweenExpression;
    }


    @Override
    public WhereJoint joint() {
        return whereJoint;
    }

    @Override
    public String column() {
        return column;
    }

    @Override
    public Object startValue() {
        return startValue;
    }

    @Override
    public Object endValue() {
        return endValue;
    }

    @Override
    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public int index() {
        return index;
    }

    @Override
    public WhereExpressionType type() {
        return WhereExpressionType.BETWEEN;
    }
}
